package com.music.server.controller;


import com.music.server.pojo.Collect;
import com.music.server.service.CollectService;
import com.music.server.utils.ResultVo;
import com.music.server.vo.CollectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 收藏 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-03-06
 */
@RestController
@RequestMapping("collect")
public class CollectController {

    @Autowired
    private CollectService collectService;

    /**
     * 添加歌曲、歌单收藏信息
     * @return
     */
    @PostMapping("save")
    public ResultVo save(@RequestBody Collect collect){
        boolean save = collectService.save(collect);
        if (save) return ResultVo.ok();
        return ResultVo.error();
    }

    /**
     * 删除歌曲、歌单收藏信息
     * @return
     */
    @DeleteMapping("delete/{id}")
    public ResultVo delete(@PathVariable Integer id){
        boolean save = collectService.removeById(id);
        if (save) return ResultVo.ok();
        return ResultVo.error();
    }


    /**
     * 分页条件查询所有的歌曲、歌单收藏信息
     * @return
     */
    @PostMapping("page/{pageNum}/{size}")
    public ResultVo page(@PathVariable Integer pageNum,@PathVariable Integer size,@RequestBody CollectVo collectVo ){

        return ResultVo.ok().data("page",collectService.page(pageNum,size,collectVo));
    }
}

